#include "GuyDeath.h"

GuyDeath::GuyDeath(QGraphicsScene *scene)
{
    root = QFileInfo(__FILE__).absolutePath();
    for(int j=0;j<6;j++){
        deathlist.append(QPixmap(root + "/res/old_death_frame" + QString::number(j + 1) + ".png"));
        deathbloodlist.append(QPixmap(root + "/res/doom_splat_frame" + QString::number(j + 1) + ".png").scaled(200, 140));
    }
    i=0;
    this->setVisible(false);
    scene->addItem(this);
}

QRectF GuyDeath::boundingRect() const{
    return QRectF(-deathlist[0].width()*0.5-20,-deathlist[0].height()*0.5-20,deathlist[0].width()*0.5-20,deathlist[0].height()*0.5-20);
}

void GuyDeath::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->drawPixmap(-deathlist[0].width() * 0.5, -deathlist[0].height() * 0.5, deathlist[i]);
    painter->drawPixmap(-deathbloodlist[0].width() * 0.5, -deathbloodlist[0].height() * 0.5, deathbloodlist[i]);
}

void GuyDeath::updateDeathAnimation()
{
    this->setVisible(true);
    i = (i+1)%6;
    this->update();
}
